package org.example.Server.controller.question;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.question.QUpdate;
import org.example.Server.model.question.Question;
import org.example.Server.service.question.QuestionService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教师试题库
 */
@RestController
@Slf4j
@RequestMapping("/youxich/question/personal")
public class QuestionController {
    @Autowired
    QuestionService questionService;

    /**
     * 加入选项类的试题资源
     * @param question
     * @return
     */
    @PostMapping
    public ResultAPI insertQS(@RequestBody Question question) {
        return questionService.insertQS(question);
    }

    /**
     * 加入简答试题资源
     * @param question
     * @return
     */
    @PostMapping("/qna")
    public ResultAPI insertQnA(@RequestBody Question question) {
        return questionService.insertQnA(question);
    }

    /**
     * 获取公共或者该教师创建的试题
     * @param tech_id
     * @return
     */
    @GetMapping
    public ResultAPI getQSList(@RequestParam(required = false) Integer tech_id,
                               @RequestParam(required = false) Integer qs_type,
                               @RequestParam(required = false) Integer difficulty,
                               @RequestParam(required = false) Integer point_id) {
        return questionService.getQSList(tech_id,qs_type,difficulty, point_id);
    }

    /**
     * 批量删除试题（全部类型
     * @param qs_ids
     * @return
     */
    @DeleteMapping("{qs_ids}")
    public ResultAPI deleteQS(@PathVariable List<Integer> qs_ids) {
        return questionService.deleteQS(qs_ids);
    }

    /**
     * 更新每一题
     * @param qUpdate
     * @return
     */
    @PutMapping
    public ResultAPI updateQS(@RequestBody QUpdate qUpdate) {
        log.info("题库更新"+qUpdate);
        return questionService.updateQS(qUpdate);
    }

    /**
     * 教师获取某一个试题的单独内容
     * @param qs_id
     * @return
     */
    @GetMapping("{qs_id}")
    public ResultAPI getQS(@PathVariable Integer qs_id) {
        return questionService.getQuestionById(qs_id);
    }
}
